from qfluentwidgets import *
from pages.HomePage.homePage_ui import Ui_Form
from PyQt6.QtWidgets import *
import datetime, time
import threading


class AppCard(CardWidget):
    def __init__(self, title, parent=None):
        super().__init__(parent)
        self.titleLabel = TitleLabel(title, self)
        self.setFixedHeight(78)



class HomePage(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.card = AppCard(title="EHS智能监测预警工业软件平台", parent=self)
        self.setupUi(self)
        self.running = True
        self.time_t = threading.Thread(target=self.startTime, args=(1,))
        self.time_t.start()

    def startTime(self, interval: int):
        try:
            while self.running:
                current_time = datetime.datetime.now()
                current_time_str = current_time.strftime("%Y-%m-%d %H:%M:%S")
                self.label_time.setText(current_time_str)
                time.sleep(interval)

        except Exception as e:
            print("error-HomePage:", e)

    def closeTime(self):
        print("关闭线程")
        self.running = False
        self.time_t.join()
